package com.xuexuehai.carrecommand.config;

import com.xuexuehai.carrecommand.job.MyJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xuexuehai
 * @mailBox xuehai.xue@QQ.com
 * @date 2021/8/23 3:07 下午
 */
@Configuration
public class MyQuartzConfig {

    @Bean
    public JobDetail jobDetail(){
        return JobBuilder
                .newJob(MyJob.class)
                .withIdentity("read-usernames-from-db")
                .storeDurably(true)
                .build();
    }

    @Bean
    public Trigger jobTrigger(){
        return TriggerBuilder
                .newTrigger()
                .forJob(jobDetail())
                .withIdentity("read-usernames-from-db")
                .withSchedule(
                        CronScheduleBuilder
                                .cronSchedule("0 15 3 * * ? "))
                                //.cronSchedule("*/3 * * * * ?"))
                .build();
    }
}
